package com.casems.controller.advice;

import com.casems.commons.execption.ParamExecption;
import com.casems.commons.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExecptionHandler {

    @ExceptionHandler(ParamExecption.class)
    public ResultVO handle(ParamExecption e) {
        log.error(e.getMessage(), e);
        return e.getCode()==null? ResultVO.failed(e.getMessage()):ResultVO.failed(e.getCode(),e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public ResultVO handle(Exception e){
        log.error(e.getMessage() ,e);
        return ResultVO.failed();
    }
}
